Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add playground RIR tab with raw and ssa processed RIR #2096

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

idavis
Copy link
Collaborator

@idavis idavis commented Jan 7, 2025

No description provided.

@idavis idavis self-assigned this Jan 7, 2025
@idavis idavis marked this pull request as ready for review January 7, 2025 21:46
e,
))]
})?;
Ok(vec![raw.to_string(), ssa.to_string()])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why convert the tuple to a vec here? You could just return the tuple. Were you fighting JavaScript?

Copy link
Collaborator Author

@idavis idavis Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I wanted to return a tuple, but the wasm bindings wouldn't let me, so instead of having to turn a tuple into vec, I just kept it in a vec to start

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also may be returning more instances of RIR to show pass steps which would be a vec eventually.

@@ -220,6 +220,21 @@ pub fn get_hir(
Ok(package.to_string())
}

#[wasm_bindgen]
pub fn get_rir(program: ProgramConfig) -> Result<Vec<String>, String> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an extra step, but for readability and type checking, please define a struct (which will be converted to a JS object) for the return type instead of a "tuple" (or JS array). Just makes it so much easier to use from the JS side.

Currently we use the serializable_type! macro. generate_docs/IDocFile in this file is an example you can follow. (It is a bit verbose, I plan to improve it in the future, but right now that's the pattern we use all over this module).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I avoided that as it is likely that there will be additional RIR returned such that we have a vec of RIR representing compilation/optimization steps so we can view the iteration of the compilation. We have other examples where we are wrapping complex types and returning arrays of them. It seemed overkill to do so when the value is just a string.

compiler/qsc/src/codegen.rs Outdated Show resolved Hide resolved
compiler/qsc/src/codegen.rs Outdated Show resolved Hide resolved
@minestarks
Copy link
Member

@idavis just noticed that the RIR tab doesn't show errors like the QIR tab does. RIR will just continue to show the last successful result which can be frustrating. Maybe you forgot to wire up the error handling somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants